package com.controller;

import com.service.IDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DepController {

    @Autowired
    private IDepService depService;

    @GetMapping("/queryAllDep")
    public String queryAllDep(Model m){
        List list=depService.findALl();
        m.addAttribute("list",list);
        return "showDep.html";

    }

    @RequestMapping("/delByIdDep")
    @ResponseBody
    public String delByIdDep(Integer id){
        if (id==null){
            return "0";
        }
        int n=depService.delById(id);
        if (n==0){
            return "1";
        }
        return "2";
    }

    @GetMapping("/searchDep")
    public String searchDep(String depName,Integer depId,Model m){
        System.out.println(depName+depId);
        List list=depService.searchDep(depName,depId);
        m.addAttribute("list",list);
        return "showDep.html";
    }





}
